var ctx;
var userName = "";
var beginDate = "";
var endDate = ""
var page = 1;
var pSize;
var pages = $("#pages").val();

function setCtx(ctx){
	this.ctx = ctx;
}

function ifNull(mess){
	if(mess == null || mess == undefined){
		mess = "";
	}
	return mess;
}

//鼠标滑入一行改变背景颜色
function mouseoverOne(target){
	 $(target).children().each(function(){
		  	    $(this).css("background","#D3F0F1");
		     });
}

//鼠标滑出一行恢复原来的背景颜色
function mouseoutOne(target){
	 $(target).children().each(function(){
	  	    $(this).css("background","");
	     });
}

//分页跳转页面
function gotoPage(page){
	
	if(parseInt(page) < 1 ){
		//当页数小于1时，停留在第一页
		page = 1;
	}
	if(parseInt(page) > parseInt(pages)){
		//当页数大于总页数时，停留在最后一页
		page = pages;
	}
	
	userName = ifNull($("#userName").val());
	beginDate = ifNull($("#beginDate").val());
	endDate = ifNull($("#endDate").val());
	pSize = ifNull($("#pSize").val());
	
	//解决ie9以下placeholder与value重复的问题
	if(userName == $("#userName").attr("placeholder")){
		userName = "";
	}
	if(beginDate == $("#beginDate").attr("placeholder")){
		beginDate = "";
	}
	if(endDate == $("#endDate").attr("placeholder")){
		endDate = "";
	}
	loadContent("/log/logList?pNo="+ page +"&userName="+ userName + "&beginDate="+ beginDate +"&endDate=" + endDate + "&pSize="+ pSize);
}

function gotoLogPage(page) {
	if(page == null){
		page = $(".inputclass").val();
	}
	if(parseInt(page) < 1 ){
		//当页数小于1时，停留在第一页
		page = 1;
	}
	if(parseInt(page) > parseInt(pages)){
		//当页数大于总页数时，停留在最后一页
		page = pages;
	}
	
	userName = ifNull($("#userName").val());
	beginDate = ifNull($("#beginDate").val());
	endDate = ifNull($("#endDate").val());
	pSize = ifNull($("#pSize").val());
	
	//解决ie9以下placeholder与value重复的问题
	if(userName == $("#userName").attr("placeholder")){
		userName = "";
	}
	if(beginDate == $("#beginDate").attr("placeholder")){
		beginDate = "";
	}
	if(endDate == $("#endDate").attr("placeholder")){
		endDate = "";
	}
	loadContent("/log/logList?pNo="+ page +"&userName="+ userName + "&beginDate="+ beginDate +"&endDate=" + endDate + "&pSize="+ pSize);
}

//条件搜索系统日志列表
function logList(){
	
	if(parseInt(page) < 1 ){
		//当页数小于1时，停留在第一页
		page = 1;
	}
	if(parseInt(page) > parseInt(pages)){
		//当页数大于总页数时，停留在最后一页
		page = pages;
	}
	userName = ifNull($("#userName").val());
	beginDate = ifNull($("#beginDate").val());
	endDate = ifNull($("#endDate").val()); 
	pSize = ifNull($("#pSize").val());
	//解决ie9以下placeholder与value重复的问题
	if(userName == $("#userName").attr("placeholder")){
		userName = "";
	}
	if(beginDate == $("#beginDate").attr("placeholder")){
		beginDate = "";
	}
	if(endDate == $("#endDate").attr("placeholder")){
		endDate = "";
	}
    var start=new Date(beginDate.replace("-", "/").replace("-", "/"));  
    var end = new Date(endDate.replace("-", "/").replace("-", "/"));  
    
    if(beginDate != "" && endDate == ""){
    	layer.msg("请选择结束时间",{
			icon: 3,
			time: 1000 //2秒关闭（如果不配置，默认是3秒）
		});
    }else if( endDate != "" && beginDate == ""){
    	layer.msg("请选择开始时间",{
			icon: 3,
			time: 1000 //2秒关闭（如果不配置，默认是3秒）
		});
    }else if(end < start){
    	layer.msg("结束时间应大于起始时间",{
			icon: 3,
			time: 1000 //2秒关闭（如果不配置，默认是3秒）
		});
    }else{
    	loadContent("/log/logList?pNo="+ page +"&userName="+ userName + "&beginDate="+ beginDate +"&endDate=" + endDate + "&pSize="+ pSize);
    } 
}

